package com.ssy.lingxi.purchase.repository;

import com.ssy.lingxi.purchase.entity.quotedprice.QuotedPrice;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Set;

/**
 *采购报价单DAO
 */
@Repository
public interface QuotedPriceRepository extends JpaRepository<QuotedPrice, Long>, JpaSpecificationExecutor<QuotedPrice> {
    QuotedPrice findByQuotedPriceNoAndCreateMemberIdAndCreateMemberRoleId(String quotedPriceNo,Long memberId, Long memberRoleId);


    QuotedPrice findByIdAndCreateMemberIdAndCreateMemberRoleId(Long id,Long memberId, Long memberRoleId);
    QuotedPrice findByPurchaseInquiryIdAndCreateMemberIdAndCreateMemberRoleId(Long id,Long memberId, Long memberRoleId);
    List<QuotedPrice> findAllByPurchaseInquiryId(Long purchaseInquiryId);
    List<QuotedPrice> findAllByPurchaseInquiryIdAndTurn(Long purchaseInquiryId,Integer turn);
    List<QuotedPrice> findAllByPurchaseInquiryIdIn(Set<Long> ids);

    List<QuotedPrice> findAllByPurchaseInquiryIdInAndCreateMemberIdAndCreateMemberRoleId(Set<Long> ids, Long memberId,Long memberRoleId);

    QuotedPrice findByQuotedPriceNo(String quotedPriceNo);

    QuotedPrice findByQuotedPriceNoAndMemberIdAndMemberRoleId(String quotedPriceNo,Long memberId, Long memberRoleId);

    QuotedPrice findByIdAndMemberIdAndMemberRoleId(Long id,Long memberId, Long memberRoleId);

    /**
     *查询审核通过的报价单
     */
    List<QuotedPrice> findAllByPurchaseInquiryIdAndInteriorState(Long purchaseInquiryId,Integer interiorState);


    boolean existsAllByPurchaseInquiryIdAndCreateMemberIdAndCreateMemberRoleIdAndTurn(Long purchaseInquiryId,Long memberId, Long memberRoleId, Integer turn);
}
